﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace CRMAdapter
{
    public static class PayByEzidebit
    {
        //Add new customer to EziDebit
        public static void AddCustomers(string DigitalKey, string YourSystemReference, string YourGeneralReference, string LastName, string FirstName, string AddressLine1, string AddressLine2, string AddressSuburb, string AddressState, string AddressPostCode, string EmailAddress, string MobilePhoneNumber, string ContractStartDate, string SmsPaymentReminder, string SmsFailedNotification, string SmsExpiredCard, string Username)
        {
            EziDebitService.NonPCIServiceClient cs = new EziDebitService.NonPCIServiceClient("BasicHttpBinding_INonPCIService1");
            EziDebitService.EziResponseOfNewCustomerXcXH3liW rs = cs.AddCustomer(DigitalKey, YourSystemReference, YourGeneralReference, LastName, FirstName, AddressLine1, AddressLine2, AddressSuburb, AddressState, AddressPostCode, EmailAddress, MobilePhoneNumber, ContractStartDate, SmsPaymentReminder, SmsFailedNotification, SmsExpiredCard, Username);
            string message = "Your customer reference is:" + rs.Data.CustomerRef;
            HttpContext.Current.Response.Write("<script type='text/javascript' language='javascript'>alert('" + message + "');</script>");
            if (rs.Data.CustomerRef != null)
                HttpContext.Current.Response.Redirect("EditBankDetails.aspx?CId=" + rs.Data.CustomerRef);
        }

        //Add new customer to EziDebit from contract page
        public static int AddCustomers1(string DigitalKey, string YourSystemReference, string YourGeneralReference, string LastName, string FirstName, string AddressLine1, string AddressLine2, string AddressSuburb, string AddressState, string AddressPostCode, string EmailAddress, string MobilePhoneNumber, string ContractStartDate, string SmsPaymentReminder, string SmsFailedNotification, string SmsExpiredCard, string Username)
        {
            EziDebitService.NonPCIServiceClient cs = new EziDebitService.NonPCIServiceClient("BasicHttpBinding_INonPCIService1");
            EziDebitService.EziResponseOfNewCustomerXcXH3liW rs = cs.AddCustomer(DigitalKey, YourSystemReference, YourGeneralReference, LastName, FirstName, AddressLine1, AddressLine2, AddressSuburb, AddressState, AddressPostCode, EmailAddress, MobilePhoneNumber, ContractStartDate, SmsPaymentReminder, SmsFailedNotification, SmsExpiredCard, Username);
            return rs.Data.CustomerRef;
        }

        //Add payment plan to EziDebit
        public static void AddPayments(string DigitalKey, string EziDebitCustomerID, string YourSystemReference, string DebitDate, long PaymentAmountInCents, string PaymentReference, string Username)
        {
            EziDebitService.NonPCIServiceClient cs = new EziDebitService.NonPCIServiceClient("BasicHttpBinding_INonPCIService1");
            EziDebitService.EziResponseOfstring rs = cs.AddPayment(DigitalKey, EziDebitCustomerID, YourSystemReference, DebitDate, PaymentAmountInCents, PaymentReference, Username);
            if (rs.Data == "S")
            {
                HttpContext.Current.Response.Write("<script type='text/javascript' language='javascript'>alert('Payment has been successfully scheduled');</script>");
                HttpContext.Current.Response.Redirect("GetEziDebitPaymentResult.aspx");
            }
            else
                HttpContext.Current.Response.Write("<script type='text/javascript' language='javascript'>alert('" + rs.ErrorMessage + "');</script>");
        }

        //Add payment plan to EziDebit form contract
        public static void AddPayments1(string DigitalKey, string EziDebitCustomerID, string YourSystemReference, string DebitDate, long PaymentAmountInCents, string PaymentReference, string Username)
        {
            EziDebitService.NonPCIServiceClient cs = new EziDebitService.NonPCIServiceClient("BasicHttpBinding_INonPCIService1");
            EziDebitService.EziResponseOfstring rs = cs.AddPayment(DigitalKey, EziDebitCustomerID, YourSystemReference, DebitDate, PaymentAmountInCents, PaymentReference, Username);
        }

        //Get payment result:
        public static void GetPaymentDetails(string DigitalKey, string PaymentReference)
        {
            EziDebitService.NonPCIServiceClient cs = new EziDebitService.NonPCIServiceClient("BasicHttpBinding_INonPCIService1");
            EziDebitService.EziResponseOfPaymentDetailTHgMB7oL payDetails = cs.GetPaymentDetail(DigitalKey, PaymentReference);
            string message = "Debit date is: " + payDetails.Data.DebitDate + "\\n" + "Payment amount is:" + payDetails.Data.PaymentAmount + "\\n" + "Payment id is:" + payDetails.Data.PaymentID + "\\n" + "Payment method is:" + payDetails.Data.PaymentMethod + "\\n" + "Payment status is:" + payDetails.Data.PaymentStatus + "\\n" + "Scheduled amount is:" + payDetails.Data.ScheduledAmount + "\\n" + "SettlementDate is:" + payDetails.Data.SettlementDate + "\\n" + "TransactionFee Client:" + payDetails.Data.TransactionFeeClient + "\\n" + "TransactionFee Customer:" + payDetails.Data.TransactionFeeCustomer;
            HttpContext.Current.Response.Write("<script type='text/javascript' language='javascript'>alert('" + message + "');</script>");
        }

        //Change schedule amount
        public static void ChangeScheduledAmounts(string DigitalKey, string EziDebitCustomerID, string YourSystemReference, int ChangeFromPaymentNumber, string ChangeFromDate, long NewPaymentAmountInCents, string ApplyToAllFuturePayments, string KeepManualPayments, string Username)
        {
            EziDebitService.NonPCIServiceClient cs = new EziDebitService.NonPCIServiceClient("BasicHttpBinding_INonPCIService1");
            EziDebitService.EziResponseOfstring res = cs.ChangeScheduledAmount(DigitalKey, EziDebitCustomerID, YourSystemReference, ChangeFromPaymentNumber, ChangeFromDate, NewPaymentAmountInCents, ApplyToAllFuturePayments, KeepManualPayments, Username);
            if (res.Data == "S")
                HttpContext.Current.Response.Write("<script type='text/javascript' language='javascript'>alert('Amount has been changed successfully.');</script>");
        }

        //Change schedule date
        public static void ChangeScheduledDates(string DigitalKey, string EziDebitCustomerID, string YourSystemReference, string ChangeFromDate, string PaymentReference, string ChangeToDate, string KeepManualPayments, string Username)
        {
            EziDebitService.NonPCIServiceClient cs = new EziDebitService.NonPCIServiceClient("BasicHttpBinding_INonPCIService1");
            EziDebitService.EziResponseOfstring res =  cs.ChangeScheduledDate(DigitalKey, EziDebitCustomerID, YourSystemReference, ChangeFromDate,PaymentReference,ChangeToDate,KeepManualPayments,Username);
            if (res.Data == "S")
                HttpContext.Current.Response.Write("<script type='text/javascript' language='javascript'>alert('Date has been changed successfully.');</script>");
            
        }
    }
}
